<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>

    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">


    <title>用户管理</title>
    <meta name="keywords" content="用户管理">
    <meta name="description" content="用户管理">

    <link rel="shortcut icon" href="favicon.ico">
    <link th:href="(${@viewConfig.getRemoteViewUrl()})+'asset/js/bootstrap/css/bootstrap.min.css'"
          href="../../asset/js/bootstrap/css/bootstrap.min.css" rel="stylesheet">
    <link th:href="(${@viewConfig.getRemoteViewUrl()})+'asset/css/fonts/iconfont.css'"
          href="../../asset/css/fonts/iconfont.css" rel="stylesheet">
    <link th:href="(${@viewConfig.getRemoteViewUrl()})+'asset/js/plugins/jqgrid/ui.jqgridffe4.css'"
          href="../../asset/js/plugins/jqgrid/ui.jqgridffe4.css" rel="stylesheet">
    <link th:href="(${@viewConfig.getRemoteViewUrl()})+'asset/css/animate.min.css'"
          href="../../asset/css/animate.min.css"
          rel="stylesheet">
    <link th:href="(${@viewConfig.getRemoteViewUrl()})+'asset/css/style.min862f.css'"
          href="../../asset/css/style.min862f.css" rel="stylesheet">


</head>

<body class="gray-bg">
<div class="animated fadeInRight">
    <div class="ibox ">
        <div id="ibox-title" class="ibox-title ">
            <div class="row">
                <form class="form-inline" id="formSearch">
                    <div class="col-sm-3 form-group">
                        <label style="width: 60px">登录名</label>
                        <input type="text" name="loginName" placeholder="请输入登录名" class="form-control">
                    </div>
                    <div class="col-sm-3 form-group">
                        <label style="width: 60px">姓名</label>
                        <input type="text" name="name" placeholder="请输入姓名" class="form-control">
                    </div>
                    <div class="col-sm-6 form-group">
                        <button id="btnRest" onclick="reset()" class="btn btn-primary btn-xs skin_blue_buttom"
                                style="float: right; margin-left: 10px" type="button"><i
                                class="icon egojit-front icon-add"></i>&nbsp;重置
                        </button>
                        <button id="btnSearch" onclick="search()" class="btn btn-warning btn-xs" type="button"
                                style="float: right;"><i class="icon egojit-front icon-search"></i>&nbsp;搜索
                        </button>

                    </div>

                </form>
            </div>

        </div>
        <div class="ibox-content" style="padding-top: 10px">
            <div id="listOprBox" class="row" style="margin-bottom: 10px">
                <button shiro:hasPermission="upms:user:edit" id="btnAdd" onclick="add()" class="btn btn-primary btn-xs "
                        type="button"><i
                        class="icon egojit-front icon-add"></i>&nbsp;添加
                </button>
                <button id="btnDelete" onclick="del()" class="btn btn-danger btn-xs " type="button"><i
                        class="icon egojit-front icon-delete"></i>&nbsp;删除
                </button>
                <button id="btnChangePwd" onclick="changePwd()" class="btn btn-primary btn-xs "
                        type="button"><i
                        class="icon egojit-front icon-pwd_setting"></i>&nbsp;密码设置
                </button>
                <button id="btnPower" onclick="roleSetting()" class="btn btn-primary btn-xs "
                        type="button"><i
                        class="icon egojit-front icon-power"></i>&nbsp;角色设置
                </button>
            </div>
            <div class="jqGrid_wrapper">
                <table id="table_list"></table>
                <div id="pager_list"></div>
                <div id="itemOpr" style="display: none">
                        <span class="center-block text-center">
                            <button id="btnItemEdit" shiro:hasPermission="upms:user:edit"
                                    class="btn btn-info btn-xs "
                                    type="button"
                                    style="margin-right: 5px;margin-left: 5px"><i
                                    class="icon egojit-front icon-edit"></i>&nbsp;修改</button>
                            <button id="btnItemDetail" shiro:hasPermission="upms:user:read"
                                    class="btn btn-info btn-xs "
                                    type="button"
                                    style="margin-right: 5px;margin-left: 5px"><i
                                    class="icon egojit-front icon-look"></i>&nbsp;查看</button>

                        </span>
                </div>
            </div>
        </div>
    </div>
</div>

<script th:src="(${@viewConfig.getRemoteViewUrl()})+'asset/js/jquery/jQuery-2.2.0.min.js'"
        src="../../asset/js/jquery/jQuery-2.2.0.min.js"></script>
<script th:src="(${@viewConfig.getRemoteViewUrl()})+'asset/js/bootstrap/js/bootstrap.min.js'"
        src="../../asset/js/bootstrap/js/bootstrap.min.js"></script>
<script th:src="(${@viewConfig.getRemoteViewUrl()})+'asset/js/plugins/peity/jquery.peity.min.js'"
        src="../../asset/js/plugins/peity/jquery.peity.min.js"></script>
<script th:src="(${@viewConfig.getRemoteViewUrl()})+'asset/js/plugins/jqgrid/i18n/grid.locale-cnffe4.js'"
        src="../../asset/js/plugins/jqgrid/i18n/grid.locale-cnffe4.js"></script>
<script th:src="(${@viewConfig.getRemoteViewUrl()})+'asset/js/plugins/jqgrid/jquery.jqGrid.minffe4.js'"
        src="../../asset/js/plugins/jqgrid/jquery.jqGrid.minffe4.js"></script>
<script th:src="(${@viewConfig.getRemoteViewUrl()})+'asset/js/plugins/layer/layer.js'"
        src="../../asset/js/plugins/layer/layer.js"></script>
<script th:src="(${@viewConfig.getRemoteViewUrl()})+'asset/js/comm.js'" src="../../asset/js/comm.js"></script>
<!--<script src="js/content.min.js?v=1.0.0"></script>-->
<script type="text/javascript">
    var $jqGridObj;

    //删除
    function del(id) {
        var selectIds = [];
        if (!id || id.length <= 0) {
            selectIds = $jqGridObj.list.jqGrid('getGridParam', 'selarrrow');
            console.log(selectIds);
        } else {
            selectIds.push(id);
        }
        if (selectIds == null || selectIds.length < 1) {
            app.tip("请选择数据!");
            return;
        }
        app.confirm("确定删除该数据？", function () {
            app.post("/admin/user/delete", {ids: JSON.stringify(selectIds)}, function (data) {
                app.close();
                app.tip("删除成功！");
                $jqGridObj.list.trigger("reloadGrid");
            })
        })
    };

    //新增
    function add() {
        app.windows("编辑", "/admin/user/edit", "900px", "550px");
    }

    //修改密码
    function changePwd(id) {
        var selectIds = [];
        if (!id || id.length <= 0) {
            selectIds = $jqGridObj.list.jqGrid('getGridParam', 'selarrrow');
            console.log(selectIds);
        } else {
            selectIds.push(id);
        }
        if (selectIds == null || selectIds.length < 1) {
            app.tip("请选择数据!");
            return;
        }
        var ids = "";
        for (i = 0; i < selectIds.length; i++) {
            ids += selectIds[i] + ",";
        }
        // var ids=JSON.stringify(selectIds);
        var url = "/admin/user/changePwd?ids=" + ids;
        app.windows("密码设置", url, "340px", "400px");
    }

    //角色设置
    function roleSetting(id) {
        var selectIds = [];
        if (!id || id.length <= 0) {
            selectIds = $jqGridObj.list.jqGrid('getGridParam', 'selarrrow');
            console.log(selectIds);
        } else {
            selectIds.push(id);
        }
        if (selectIds == null || selectIds.length < 1) {
            app.tip("请选择数据用户!");
            return;
        }
        if (selectIds.length > 1) {
            app.tip("只能选择一个用户!");
            return;
        }
        id = selectIds[0];
        app.windows("设置角色", "/admin/role/selectRole?id=" + id, "900px", "550px");
    }

    //编辑
    function edit(id) {
        app.windows("详情", "/admin/user/edit?id=" + id, "900px", "550px");
    }

    //详情
    function detail(id) {
        app.windows("详情", "/admin/user/detail?id=" + id, "900px", "500px");
    }

    /**
     * 重置
     */
    function reset() {
        $("#formSearch").reset();
    }

    $(document).ready(function () {
        //列表初始化
        $jqGridObj = app.list({
            url: "/admin/user/index",
            colNames: ["姓名", "登录名", "联系方式", "邮箱", "公司名称", "所属车队", "操作"],
            colModel: [
                {name: "name", index: "name", width: 50},
                {name: "loginName", index: "loginName", width: 50},
                {name: "mobile", index: "mobile", width: 55},
                {name: "email", index: "email", editable: true, width: 70},
                {name: "companyName", index: "companyName", editable: true, width: 130},
                {name: "carTeamName", index: "carTeamName", editable: true},

                {
                    name: "id",
                    index: "id",
                    width: 90,
                    formatter: function (cellvalue, options, rowObject) {
                        var html = $jqGridObj.initOpr([
                            {id: "#btnItemEdit", click: "edit(\'" + cellvalue + "\')"},
                            {id: "#btnItemDetail", click: "detail(\'" + cellvalue + "\')"}
                        ]);
                        console.log(html);
                        return html;
                    }
                }
            ]
        });

    });
</script>
</body>
</html>
